package com.lyz.dataStructure.algorithm.用友2020;


import java.util.Scanner;

public class Main1 {

    public static TreeNode method1(String fStr,String mStr){
        TreeNode treeNode = new TreeNode(fStr.charAt(0),null,null);

        if(fStr.length()==1){
            return treeNode;
        }
        String[] strings = method2(fStr, mStr);
        if(strings[2] != null && strings[2].length() != 0){
            treeNode.lNode = method1(strings[0],strings[2]);
        }
        if(strings[3]!=null && strings[3].length() != 0){
            treeNode.rNode = method1(strings[1],strings[3]);
        }
        return treeNode;
    }
    public static String[] method2(String fStr,String mStr){

        String[] result = new String[4];
        if(fStr.length()==1){
            return result;
        }
        String[] middleSplit = new String[2];
        mStr.split(fStr.charAt(0)+"");
        middleSplit[0]=mStr.split(fStr.charAt(0)+"")[0];
        if (mStr.split(fStr.charAt(0)+"").length==1){
            middleSplit[1]="";
        }else {
            middleSplit[1] = mStr.split(fStr.charAt(0)+"")[1];
        }
        int middleLeftCount = middleSplit[0].length();
        String[] frontSplit = new String[2];
        frontSplit[0] = fStr.substring(1,middleLeftCount+1);
        frontSplit[1] = fStr.substring(middleLeftCount+1);
        result[0] = frontSplit[0];
        result[1] = frontSplit[1];
        result[2] = middleSplit[0];
        result[3] = middleSplit[1];
        return result;
    }

    public static void method3(TreeNode rootNode){
        if(rootNode.lNode!=null){
            method3(rootNode.lNode);
        }
        if(rootNode.rNode!= null){
            method3(rootNode.rNode);
        }
        System.out.print(rootNode.value);

    }
    //ABCDEFGH,BDCEAFHG
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        String s1 = sc.nextLine();
        String[] st =s.split(",");
        for(int i =0;i<2;i++){
          // String s = st[i].charAt(i);

        }
        TreeNode rootNode = method1(s,s1);
        method3(rootNode);
    }
}


class TreeNode{
    public char value;
    public TreeNode lNode;
    public TreeNode rNode;

    public TreeNode(char value, TreeNode lNode, TreeNode rNode) {
        this.value = value;
        this.lNode = lNode;
        this.rNode = rNode;
    }
}
